package com.tl.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tl.common.annotation.Log;
import com.tl.common.core.controller.BaseController;
import com.tl.common.core.domain.AjaxResult;
import com.tl.common.enums.BusinessType;
import com.tl.app.domain.AppClerk;
import com.tl.app.service.IAppClerkService;
import com.tl.common.utils.poi.ExcelUtil;
import com.tl.common.core.page.TableDataInfo;

/**
 * 店员Controller
 * 
 * @author suhp
 * @date 2024-07-07
 */
@RestController
@RequestMapping("/app/clerk")
public class AppClerkController extends BaseController
{
    @Autowired
    private IAppClerkService appClerkService;

    /**
     * 查询店员列表
     */
    @PreAuthorize("@ss.hasPermi('app:clerk:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppClerk appClerk)
    {
        startPage();
        List<AppClerk> list = appClerkService.selectAppClerkList(appClerk);
        return getDataTable(list);
    }

    /**
     * 导出店员列表
     */
    @PreAuthorize("@ss.hasPermi('app:clerk:export')")
    @Log(title = "店员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppClerk appClerk)
    {
        List<AppClerk> list = appClerkService.selectAppClerkList(appClerk);
        ExcelUtil<AppClerk> util = new ExcelUtil<AppClerk>(AppClerk.class);
        util.exportExcel(response, list, "店员数据");
    }

    /**
     * 获取店员详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:clerk:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(appClerkService.selectAppClerkByUserId(userId));
    }

    /**
     * 新增店员
     */
    @PreAuthorize("@ss.hasPermi('app:clerk:add')")
    @Log(title = "店员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppClerk appClerk)
    {
        return toAjax(appClerkService.insertAppClerk(appClerk));
    }

    /**
     * 修改店员
     */
    @PreAuthorize("@ss.hasPermi('app:clerk:edit')")
    @Log(title = "店员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppClerk appClerk)
    {
        return toAjax(appClerkService.updateAppClerk(appClerk));
    }
    
    /**
     * 审核店员
     */
    @Log(title = "店员", businessType = BusinessType.UPDATE)
    @PostMapping("/check")
    public AjaxResult check(@RequestBody AppClerk appClerk)
    {
    	appClerkService.checkAppClerk(appClerk);
        return AjaxResult.success();
    }

    /**
     * 删除店员
     */
    @PreAuthorize("@ss.hasPermi('app:clerk:remove')")
    @Log(title = "店员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(appClerkService.deleteAppClerkByUserIds(userIds));
    }
}
